# # 使用yield方式创建生成器
# def fibnacci(num):
#     num1 = 0
#     num2 = 1
#
#     # 记录当前生成数据的索引
#     current_index = 0
#     while current_index < num:
#         # 使用变量保存num1上一次存储的数据
#         result = num1
#
#         # 在此生成数据
#         num1, num2 = num2, num1 + num2
#
#         # 数据生成完成需要对下标+1
#         current_index += 1
#
#         yield result
#
#
# f = fibnacci(50)
#
# for value in f:
#     print(value)

# 使用yield方式创建生成器
# def fibnacci(num):
#     num1 = 0
#     num2 = 1
#
#     # 记录当前生成数据的索引
#     current_index = 0
#     while current_index < num:
#         # 数据生成完成需要对下标+1
#         current_index += 1
#
#         yield num1
#
#         # 在此生成数据
#         num1, num2 = num2, num1 + num2
#
#
# f = fibnacci(10)
#
# for value in f:
#     print(value)


def fibnacci(num):
    result = list()
    num1 = 0
    num2 = 1
    for i in range(num):
        result.append(num1)
        num1, num2 = num2, num1 + num2
    return result


data = fibnacci(10)
print(data)
